package com.ymatou.iapi.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.IdcardBean;
import com.ymatou.iapi.userservice.parameter.SetIdcardBean;
import com.ymatou.iapi.userservice.service.IdcardCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.utils.TestDataManager;
/**
*查询身份证信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_Idcard{
	private static IdcardBean idcardBean;
	private static IdcardCall idcardCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询身份证信息");
	}

	@Before
	public void caseUp() {
		idcardBean=new IdcardBean();
		idcardCall=new IdcardCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(idcardCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Idcard_001() {
		Logger.start(true,"查询身份证信息成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			
			SetIdcardBean setidcardBean=new SetIdcardBean();
			setidcardBean=JUserCallService.initSetIdcardBean(userId);
			JUserCallService.SetIdcardCall(setidcardBean);
			idcardBean.setUserId(userId);
			idcardCall.setData(idcardBean);
			idcardCall.callService();			
			Logger.verifyEquals("true", idcardCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", idcardCall.getString("ResponseCode"), "验证ResponseCode");
			JsonObject Result = idcardCall.getJsonObject().get("Result").getAsJsonObject();
			Logger.verifyEquals(setidcardBean.getIdCardName(), Result.get("idCardName").getAsString(), "验证idCardName");
			Logger.verifyEquals(setidcardBean.getIdCardNum(), Result.get("idCardNum").getAsString(), "验证idCardNum");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_Idcard_002() {
		Logger.start(true,"不输入userid失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			
			SetIdcardBean setidcardBean=new SetIdcardBean();
			setidcardBean=JUserCallService.initSetIdcardBean(userId);
			JUserCallService.SetIdcardCall(setidcardBean);
//			idcardBean.setUserId(userId);
			idcardCall.setData(idcardBean);
			idcardCall.callService();			
			Logger.verifyEquals("false", idcardCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", idcardCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_Idcard_003() {
		Logger.start(true,"未设置身份信息用户查询结果为空");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			
//			SetIdcardBean setidcardBean=new SetIdcardBean();
//			setidcardBean=JUserCallService.initSetIdcardBean(userId);
//			JUserCallService.SetIdcardCall(setidcardBean);
			idcardBean.setUserId(userId);
			idcardCall.setData(idcardBean);
			idcardCall.callService();			
			Logger.verifyEquals("true", idcardCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", idcardCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals(null,idcardCall.getJsonObject().get("Result"), "验证没有Result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_Idcard_004() {
		Logger.start(true,"无此用户失败");
		try {
			
			idcardBean.setUserId(-10000);
			idcardCall.setData(idcardBean);
			idcardCall.callService();			
			Logger.verifyEquals("true", idcardCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", idcardCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals(null,idcardCall.getJsonObject().get("Result"), "验证没有Result");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Idcard_005() {
		Logger.start(true,"修改用户信息后查询身份证信息成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			
			SetIdcardBean setidcardBean=new SetIdcardBean();
			setidcardBean=JUserCallService.initSetIdcardBean(userId);
			JUserCallService.SetIdcardCall(setidcardBean);
			
			setidcardBean=JUserCallService.initSetIdcardBean(userId);
			JUserCallService.SetIdcardCall(setidcardBean);
			
			idcardBean.setUserId(userId);
			idcardCall.setData(idcardBean);
			idcardCall.callService();			
			Logger.verifyEquals("true", idcardCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", idcardCall.getString("ResponseCode"), "验证ResponseCode");
			JsonObject Result = idcardCall.getJsonObject().get("Result").getAsJsonObject();
			Logger.verifyEquals(setidcardBean.getIdCardName(), Result.get("idCardName").getAsString(), "验证idCardName");
			Logger.verifyEquals(setidcardBean.getIdCardNum(), Result.get("idCardNum").getAsString(), "验证idCardNum");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}